package com.example.wisdomclassroomapi.domain.repository;

import com.example.wisdomclassroomapi.domain.entity.AuthRoleEntity;
import com.example.wisdomclassroomapi.infrastructure.mapper.AuthRoleMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;
import java.util.List;
/**
 * @Package: com.example.wisdomclassroomapi.domain.repository
 * @Description: <>
 * @Author: scholes
 * @CreateDate: 2022-04-18
 * @UpdateUser: scholes
 * @UpdateDate: 2022-04-18
 * @UpdateRemark: <>
 * @Version: 1.0
 */
@Repository
public class AuthRoleRepository {
    @Resource
    private AuthRoleMapper authRoleMapper;

    public void add(AuthRoleEntity entity) {
       authRoleMapper.insert(entity);
    }

    public AuthRoleEntity findById(String id) {
        return authRoleMapper.selectById(id);
    }

    public int updateById(AuthRoleEntity entity) {
        return authRoleMapper.updateById(entity);
    }

    public int deleteById(String id) {
        return authRoleMapper.deleteById(id);
    }

    public IPage<AuthRoleEntity> page(AuthRoleEntity entity,IPage page) {
        QueryWrapper<AuthRoleEntity> wrapper = new QueryWrapper<>();
            if (StringUtils.isNotBlank(entity.getName())){
            wrapper.eq("name",entity.getName());
            }
            if (StringUtils.isNotBlank(entity.getCode())){
            wrapper.eq("code",entity.getCode());
            }
            if (StringUtils.isNotBlank(entity.getType())){
            wrapper.eq("type",entity.getType());
            }
            if (StringUtils.isNotBlank(entity.getRemarks())){
            wrapper.eq("remarks",entity.getRemarks());
            }
            if (StringUtils.isNotBlank(entity.getStatus())){
            wrapper.eq("status",entity.getStatus());
            }
        return authRoleMapper.selectPage(page, wrapper);
    }

    public List<AuthRoleEntity> list(AuthRoleEntity entity) {
        QueryWrapper<AuthRoleEntity> wrapper = new QueryWrapper<>();
            if (StringUtils.isNotBlank(entity.getName())){
            wrapper.eq("name",entity.getName());
            }
            if (StringUtils.isNotBlank(entity.getCode())){
            wrapper.eq("code",entity.getCode());
            }
            if (StringUtils.isNotBlank(entity.getType())){
            wrapper.eq("type",entity.getType());
            }
            if (StringUtils.isNotBlank(entity.getRemarks())){
            wrapper.eq("remarks",entity.getRemarks());
            }
            if (StringUtils.isNotBlank(entity.getStatus())){
            wrapper.eq("status",entity.getStatus());
            }
        return authRoleMapper.selectList(wrapper);
    }

}